import { chain } from 'youwilllike'
import { FunctionTypes } from '../types/func'
import { ASTResult } from '../types/ops'

export function subFaceValue(contentItem: FunctionTypes) {
  const returns = (contentItem as FunctionTypes).return
  // 没有函数签名
  const curReturn = contentItem.doc?.tags.find(tagsItem => tagsItem.title === 'return')
  if (!returns) {
    // 也没有doc注释返回值
    if (!curReturn) return chain.StopBackwardExecution.call(this, 'unkown')
  }
  // return存在并且doc return字段不存在返回any
  if (returns && !curReturn) return chain.StopBackwardExecution.call(this, returns)
  // return存在并且docreturn也存在则进入下一步
  return { returns, curReturn }
}
type mergeReturndocTypes = { returns: string; curReturn: { title: string; description: string } }
export function mergeReturndoc({ returns, curReturn }: mergeReturndocTypes) {
  return `*(\`${returns}\`)*: ${curReturn.description}`
}
